﻿using System.Collections.Generic;
using System.Text.RegularExpressions;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration;
using System;

namespace AsNum.Common.EntLib.Validation.Adapters {
    /// <summary>
    /// 
    /// </summary>
    public class RegexClientAdapter : BaseClientAdapter<RegexValidatorData> {

        public RegexClientAdapter(RegexValidatorData data , Dictionary<string , Tuple<string , string>> map , bool isSub = false)
            : base ( data , map , isSub ) {

            this.AddRule ( RuleKeys.Regex ,
                string.Format ( "/{0}/{1}{2}" ,
                this.ValidatorData.Pattern ,
                ( this.ValidatorData.Options & RegexOptions.IgnoreCase ) == RegexOptions.IgnoreCase ? "i" : "" ,
                ( this.ValidatorData.Options & RegexOptions.Multiline ) == RegexOptions.Multiline ? "g" : ""
            ) );
        }


        public override RuleTypes RuleType {
            get {
                return RuleTypes.Regex;
            }
        }
    }
}
